package com.ydy.data.controller;

import com.ydy.common.BaseController;
import com.ydy.common.model.Menu;
import com.ydy.common.model.Permissions;
import com.ydy.common.util.ParamsUtil;
import com.ydy.common.vo.PageInfo;
import com.ydy.data.service.MenuInfoService;
import org.apache.commons.collections4.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.LinkedHashMap;
import java.util.List;

@RestController
public class MenuInfoController extends BaseController {

    @Autowired
    private MenuInfoService menuInfoService;

    /**
     * 查询菜单信息
     * @Title: queryMenusInfo
     * @author: dy.yin 2021/4/2 10:05
     * @param: [request]
     * @return: java.lang.Object
     * @throws
     */
    @GetMapping("/queryMenuInfo")
    public Object queryMenuInfo(HttpServletRequest request){
        PageInfo pageInfo = ParamsUtil.getPageInfo(request);
        Menu menu = ParamsUtil.getBeanParam(new Menu(),request);

        List<Menu> menusList = menuInfoService.queryMenuInfo(menu,pageInfo);
        pageInfo.setPageResult(menusList);
        return pageInfo;
    }

    /**
     * 提交菜单信息
     * @Title: submitMenuInfo
     * @author: dy.yin 2021/4/12 9:33
     * @param: [menu]
     * @return: java.lang.Object
     * @throws
     */
    @PostMapping("/submitMenuInfo")
    public Object submitMenuInfo(@RequestBody Menu menu){
        menuInfoService.submitMenuInfo(menu);
        return retResultVo();
    }

    /**
     * 删除菜单信息
     * @Title: deleteMenuInfo
     * @author: dy.yin 2021/4/12 9:34
     * @param: [map]
     * @return: java.lang.Object
     * @throws
     */
    @PostMapping("/deleteMenuInfo")
    public Object deleteMenuInfo(@RequestBody LinkedHashMap<String,Object> map){
        String menuCode = MapUtils.getString(map,"menuCode");
        menuInfoService.deleteMenuInfo(menuCode);
        return retResultVo();
    }
}
